/**
 * TimeUtils.java
 * com.jamin.aabill.utils
 *
 * Function： TODO 
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 2012-9-18 		wangjieming
 *
 * Copyright (c) 2012, TNT All Rights Reserved.
 */

package com.jamin.aabill.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * ClassName:TimeUtils
 *
 * @author   wangjieming
 * @version  1.0
 * @since    v1.0
 * @Date	 2012-9-18 上午11:38:57 
 */
public class TimeUtils {


	/**
	 * 将时间戳转成String 如果是当天保留时间<br>
	 * "yyyy-MM-dd HH:mm:ss"
	 * @param time
	 * @return
	 */
	public static String FormatTimeForm(long time) {
		Date today = new Date(System.currentTimeMillis());
		Date date = new Date(time);
		if(new SimpleDateFormat("yyyy").format(date).equals(new SimpleDateFormat("yyyy").format(today)) 
				&& new SimpleDateFormat("MM").format(date).equals(new SimpleDateFormat("MM").format(today))
				&& new SimpleDateFormat("dd").format(date).equals(new SimpleDateFormat("dd").format(today))){
			SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
			return formatter.format(date);
		}else{
			SimpleDateFormat formatter = new SimpleDateFormat("MM-dd");
			return formatter.format(date);
		}
	}



	/**
	 * 将时间戳转化成格式化的时间<br>
	 * "yyyy-MM-dd HH:mm:ss"<br>
	 * @method FormatTimeForm
	 * @param time
	 * @return
	 * @throws 
	 * @since v1.0
	 */
	public static String FormatTimeForm(long time , String format) {
		SimpleDateFormat formatter = new SimpleDateFormat(format);
		return formatter.format(new Date(time));
	}


	/**
	 * 从DateTimePicker中得到日期时间戳
	 * @method FormatTimeFromDatePicker
	 * @param year
	 * @param mounth
	 * @param day
	 * @return
	 * @throws 
	 * @since v1.0
	 */
	public static long FormatTimeFromDatePicker(int year , int mounth , int day) {
		Utils.log( "TimeUtils" , "year = " + year);
		Utils.log( "TimeUtils" , "mounth = " + mounth);
		Utils.log( "TimeUtils" , "day = " + day);
		SimpleDateFormat format =   new SimpleDateFormat( "yyyy-MM-dd" );
		try {
			Date date = format.parse( year + "-" + mounth + "-" + day );
			return date.getTime();
		} catch (ParseException e) {
		} 
		return -1;
	}













}

